import { updateNetworkFreeAmountVisibleStrategy } from '@/api/network'
import { ref } from 'vue'

/**
 * 免费额度查看策略服务
 */
export default function () {
  const updateFreeAmountVisibleStrategyLoading = ref(false)
  const updateFreeAmountVisibleStrategyForm = ref<{
    networkIds: Array<string>
    allowSelectAmount: boolean
  }>({
    networkIds: [],
    allowSelectAmount: true,
  })

  const updateFreeAmountVisibleStrategy = async () => {
    try {
      updateFreeAmountVisibleStrategyLoading.value = true
      const res = await updateNetworkFreeAmountVisibleStrategy(
        updateFreeAmountVisibleStrategyForm.value.networkIds,
        updateFreeAmountVisibleStrategyForm.value.allowSelectAmount,
      )
      updateFreeAmountVisibleStrategyLoading.value = false
      return res.data
    } catch (error) {
      updateFreeAmountVisibleStrategyLoading.value = false
    }
  }

  return {
    updateFreeAmountVisibleStrategyForm,
    updateFreeAmountVisibleStrategyLoading,
    updateFreeAmountVisibleStrategy,
  }
}
